package com.hyts.network.base;


import com.hyts.network.config.DefaultNetwork;
import com.hyts.network.config.SystemProperties;

/**
 * project-name:gitee-extends-toolbox
 * package-name:com.hyts.ext.network.base
 * author:Libo/Alex
 * create-date:2018-10-27 12:41
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于:
 */
public abstract class ServerFactoryBean<T> {

    /**
     * field-name: port
     * field-type: int
     * description: 端口
     */
    private int port = 0;

    /**
     * field-name: server
     * field-type: T
     * description: 服务
     */
    private T server;

    /**
     * field-name: singleCpuThreadNum
     * field-type: int
     * description: 单cpu 线程数大小
     */
    private int singleCpuThreadNum;

    /**
     * field-name:tryReconnectedTimes
     * field-type: int
     * description: 记录当前绑定重试册数
     */
    private int tryReconnectedTimes;
    


    public ServerFactoryBean(int port, T server) {
        this.server = server;
        this.port = (port<=0)?DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
        this.singleCpuThreadNum = (singleCpuThreadNum<=0)?SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
        this.tryReconnectedTimes = (tryReconnectedTimes<=0)?SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }

    public ServerFactoryBean(T server) {
        this.server = server;
        this.port = (port<=0)?DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
        this.singleCpuThreadNum = (singleCpuThreadNum<=0)?SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
        this.tryReconnectedTimes = (tryReconnectedTimes<=0)?SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }

    public ServerFactoryBean(T server, int singleCpuThreadNum, int tryReconnectedTimes) {
        this.server = server;
        this.port = (port<=0)?DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
        this.singleCpuThreadNum = (singleCpuThreadNum<=0)?SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
        this.tryReconnectedTimes = (tryReconnectedTimes<=0)?SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }

    public ServerFactoryBean(T server, int singleCpuThreadNum) {
        this.port = (port<=0)?DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
        this.server = server;
        this.singleCpuThreadNum = (singleCpuThreadNum<=0)?SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
        this.tryReconnectedTimes = (tryReconnectedTimes<=0)?SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }

    public int getPort() {
       return this.port = port <= 0? DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
    }

    public void setPort(int port) {
        this.port = port <= 0? DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT:port;
    }

    public T getServer() {
        return server;
    }


    public void setServer(T server) {
        this.server = server;
    }

    public int getSingleCpuThreadNum() {
       return this.singleCpuThreadNum = singleCpuThreadNum <= 0 ? SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
    }


    public void setSingleCpuThreadNum(int singleCpuThreadNum) {
        this.singleCpuThreadNum = singleCpuThreadNum <= 0 ?SystemProperties.DEFAULT_SINGLE_CORE_THREAD_NUM:singleCpuThreadNum;
    }

    public int getTryReconnectedTimes() {
        return tryReconnectedTimes <= 0 ? SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }

    public void setTryReconnectedTimes(int tryReconnectedTimes) {
        this.tryReconnectedTimes = tryReconnectedTimes <= 0 ? SystemProperties.DEFAULT_RETRY_CONNECTION_TIMES:tryReconnectedTimes;
    }
}
